home *** CD-ROM | disk | FTP | other *** search
- unit Sum1;
- { PC Plus sample Delphi program.
- Illustrates variable declaration, simple maths and
- string conversions }
-
- { The following code is all inserted automatically by Delphi }
- interface
-
- { These are the source code units available to this program }
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- { Delphi declares the main form used in the program and the }
- { visual objects it contains - such as the button and Edit box }
- type
- TForm1 = class(TForm)
- Edit1: TEdit;
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- { The procedure which is run when the Button1 object is clicked }
- { This is the only piece of code which I (rather than Delphi) have }
- { written in this program. }
- procedure TForm1.Button1Click(Sender: TObject);
- var
- { First, I've declared two variables }
- i : integer;
- s : string;
- { Now I begin the coding section }
- begin
- { It's good practice to initialise variables at the outset }
- s := '10';
- { The StrToInt function returns the string, 's', as an integer }
- { I have assigned the integer value to the variable, 'i' }
- i := StrToInt( s ); { i = 10 }
- { Now I've multiplied i by itself. The result can then be }
- { assigned back to the original variable, 'i' }
- i := i * i; { i = 100 }
- { I want to display this result in the edit box, Edit1. }
- { But the contents of Edit1 (it's Text property) is a string }
- { Therefore I must convert i into a string representation. }
- { The IntToStr returns a string which I can then assign to }
- { the variable, 's'. }
- s := IntToStr( i );
- { The Edit1's object's 'Text' property is assigned the value }
- { of the string, 's'. So '100' appears in the edit box. }
- Edit1.Text := s;
- end;
-
- end.
-